package qc.module.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qc.module.demo.dto.clazz.ClassDto;
import qc.module.demo.entity.Class;
import qc.module.demo.mapper.ClassMapper;
import qc.module.demo.repository.ClassRepository;

import java.util.List;

@Service
public class ClassService {
    private ClassRepository repository;

    @Autowired
    public void setClassRepository(ClassRepository repository) {
        this.repository = repository;
    }

    /**
     * 获取所有班级信息
     *
     * @return 班级信息集合
     */
    public List<ClassDto> getAll() {
        LambdaQueryWrapper<Class> wrapper = new LambdaQueryWrapper<>();
        // 按班级编号排序
        wrapper.orderByAsc(Class::getNo);

        // 查询数据
        List<Class> classes = repository.selectList(wrapper);

        if (classes != null && !classes.isEmpty())
            return ClassMapper.MAPPER.toDtoList(classes);

        return null;
    }
}
